<?php
/**
 * 微信授权
 */
$corpid = "wx39002761ac0abcba";
$corpsecret = "6mcuUwF1kC3-QKWZIUWch77Qz2pVNMoEli79-zq-tTM";
$api = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$corpid}&corpsecret={$corpsecret}";
$json = httpReq($api);
$arr  = json_decode($json, true);
$wxtk = $arr['access_token'];
setcookie('test_wxtk', $wxtk, time() + 7200);
return $wxtk;


// http请求
function httpReq($url, $data = null)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
    if ($data) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}